package com.tamir.template.express.handle;

import com.tamir.template.bean.TNode;
import com.tamir.template.config.TemplateNodeTypeConfig;
import com.tamir.template.context.TemplateContext;

import java.util.List;
import java.util.Map;

/**
 * @author : tanggh
 * @description :〈描述〉
 * @date : 2016/10/31
 */
public class DefaultMapValueHandle extends AbstractExpressValueHandle
{
    /**
     * 获取当前的值
     *
     * @param node
     * @param context
     * @return
     */
    @Override
    public Object getObject(TNode node, TemplateContext context) throws Exception
    {
        return null;
    }

    @Override
    public String generateText(TNode node, TemplateContext context) throws Exception
    {
        StringBuffer textBuffer = new StringBuffer();
        if(node.gettLogicType() != null){

            Map map = (Map)this.getInputObject(node, context);
            for (Object obj : map.entrySet()){
                //设置输出值
                node.setOutValue(obj);
                List<TNode> subList = node.getSubNodeList();
                if(subList != null && !subList.isEmpty()){
                    for (TNode subNode : subList){
                        textBuffer.append(TemplateNodeTypeConfig.getInstance().getITExpressValueHandle
                                (subNode).generateText(subNode, context));
                    }
                }
            }
        }

        return textBuffer.toString();
    }
}
